from general_utilities import *
from graphics_utilities import *

class Basic_monster_info:
  def __init__(self,name,
               tile_xy,new_tileset=0,from_color=None,to_color=None,chameleon=0,monochrome=0,
               description="",
               avg_original_hp=1,avg_original_mp=0,
               melee_hit_chance=0.5,missile_hit_chance=0,
               avg_melee_damage=3,avg_missile_damage=0,
               melee_verb="hits",
               armor=5,magic_resistance=5,
               fire_resistance=0,fire_immunity=0,evasive=0,protected_from_missiles=0,immune_to_poison=0,immune_to_enchantments=0,
               move_cost=1,melee_cost=1,missile_cost=1,
               knockback=0,melee_burns=0,poison_bite=0,
               undead=0,dragon=0,
               dozy=0,alert=0,
               level=1,
               treasure_carrier=0,key_carrier=0,
               flying=0, moves_through_flame_only=0, immobile=0, avoids_fire=1, avoids_pits=1, web_walk=0, can_swim=0, moves_through_water_only=0,
               size=SZ_MEDIUM,
               can_be_met_alone=1, can_be_met_in_groups=0, can_be_met_with=[], themes=[]):
    self.name = name
    if description=="":
      self.description = name 
    else:
      self.description = description
    self.tile_xy = tile_xy
    self.new_tileset = new_tileset
    self.from_color = from_color
    self.to_color = to_color
    self.chameleon = chameleon
    self.monochrome = monochrome
    self.tile = None # fill this in later, using the fields above
    self.avg_original_hp = avg_original_hp 
    self.avg_original_mp = avg_original_mp
    self.melee_hit_chance = melee_hit_chance
    self.avg_melee_damage = avg_melee_damage
    self.armor = armor
    self.magic_resistance = magic_resistance
    self.missile_hit_chance = missile_hit_chance
    self.avg_missile_damage = avg_missile_damage
    self.mp_regeneration_boost = 0
    self.fire_resistance = fire_resistance
    self.fire_immunity = fire_immunity
    if (fire_immunity==1 or avoids_fire==0) and not flying:
      self.avoids_fire = 0
    else:
      self.avoids_fire = 1
    if flying or avoids_pits==0:
      self.avoids_pits = 0
    else:
      self.avoids_pits = 1
    if immune_to_poison or undead or poison_bite:
      self.immune_to_poison = 1
    else:
      self.immune_to_poison = 0
    self.immune_to_enchantments = immune_to_enchantments
    self.melee_burns = melee_burns # 1 is all damage fire resistable, 0.5 is only half
    self.poison_bite = poison_bite # 1 is ordinary, 2 is super
    self.flying = flying
    if flying or can_swim:
      self.can_swim = 1
    else:
      self.can_swim = 0
    self.immobile = immobile
    self.moves_through_flame_only = moves_through_flame_only
    self.moves_through_water_only = moves_through_water_only
    self.web_walk = web_walk
    self.protected_from_missiles = protected_from_missiles
    self.evasive = evasive
    self.size = size
    self.move_cost = move_cost
    self.missile_cost = missile_cost
    self.melee_cost = melee_cost
    self.melee_verb = melee_verb
    self.knockback = knockback
    self.undead = undead
    self.dragon = dragon
    self.treasure_carrier = treasure_carrier
    self.level = level
    self.key_carrier = key_carrier # improve this later
    if alert:
      self.hearing = 1.5
    elif dozy:
      self.hearing = 0.5
    else:
      self.hearing = 1 # average
    self.can_be_met_alone = can_be_met_alone
    self.can_be_met_in_groups = can_be_met_in_groups
    self.can_be_met_with = can_be_met_with # [M_ code] for monsters it can lead
    self.themes = themes # [E_ code]

class Monster_library:
  def __init__(self):
    self.m = {} # key is M_ code, value is derived from Basic_monster_info
    self.m[M_SHAMBLER] = Basic_monster_info(name="the shambling mound",tile_xy=(17,17),
                                            description="A great heap of mobile vegetation. It seems to possess some rudimentary intelligence, or at least an ability to creep towards intruders.",
                                            avg_original_hp=12,
                                            avg_melee_damage=4,   
                                            move_cost=1.2,
                                            dozy=1,
                                            avoids_pits=0,
                                            level=3,
                                            size=SZ_LARGE)
    self.m[M_GOBLIN] = Basic_monster_info(name="the goblin",tile_xy=(43,13),
                                          description="A nasty little goblin with a spear. Green and ugly, like something you've sneezed up. Get him before he gets you!",
                                          avg_original_hp=6,
                                          avg_melee_damage=3,                                         
                                          move_cost=1,
                                          level=2,
                                          can_be_met_in_groups=1,
                                          themes=[E_GOBLIN,E_HUMANOID],
                                          size=SZ_SMALL)
    self.m[M_SKELETON] = Basic_monster_info(name="the animated skeleton",tile_xy=(38,20),
                                            description="The animated skeleton clatters towards you, its teeth clacking and rattling!",
                                            fire_resistance=1,
                                            avg_original_hp=6,
                                            avg_melee_damage=5,
                                            move_cost=1.2,
                                            level=2,
                                            themes=[E_UNDEAD],
                                            can_be_met_alone=0,
                                            can_be_met_in_groups=1,
                                            undead=1)    
    self.m[M_BAT] = Basic_monster_info(name="the giant bat", tile_xy=(0,16),
                                       description="If you wake these bats up, they will fly round your head and may bite you!",
                                       flying=1,
                                       dozy=1,
                                       evasive=1,
                                       avg_original_hp=2,
                                       avg_melee_damage=2,
                                       move_cost=0.5,
                                       melee_cost=0.5,
                                       melee_verb="bites",
                                       can_be_met_in_groups=1,
                                       size=SZ_SMALL)
    self.m[M_HARPY] = Basic_monster_info(name="the harpy", tile_xy=(10,19),
                                         description="Harpies are vile pests - ill-mannered, loud, smelly, cruel and greedy! If they see you they will flap straight towards you and not give you a moment's peace.",
                                         flying=1,
                                         evasive=1,
                                         move_cost=0.8,
                                         avg_melee_damage=3,
                                         avg_original_hp=7,
                                         melee_verb="claws",
                                         level=3,
                                         can_be_met_in_groups=1,
                                         size=SZ_SMALL)
    self.m[M_LEPRECHAUN] = Basic_monster_info(name="the leprechaun", tile_xy=(4,11), from_color=orange, to_color=green,
                                              description="This little Irish rascal has a treasure in his knapsack, and he'll lead you a merry dance.",
                                              move_cost=0.8,
                                              avg_original_hp=12,
                                              treasure_carrier=1,
                                              armor=8,magic_resistance=13,
                                              level=3,
                                              themes=[E_HUMANOID],
                                              size=SZ_SMALL)
    self.m[M_CHAMELEON] = Basic_monster_info(name="the giant chameleon", tile_xy=(15,19), chameleon=1,
                                             description="This giant lizard is almost impossible to see; it blends in with its surroundings.",
                                             move_cost=1.2,
                                             melee_verb="bites",
                                             avg_original_hp=13,
                                             avg_melee_damage=6,
                                             protected_from_missiles=1,
                                             level=3,
                                             themes=[E_DISGUISED],
                                             size=SZ_LARGE)
    self.m[M_STATUE] = Basic_monster_info(name="the statue", tile_xy=(12,4), monochrome=1,
                                          description="A tall statue stands here, depicting a warrior from ancient times. Its face is carved into a forbidding scowl.",                                          fire_immunity=1,
                                          immobile=1,
                                          protected_from_missiles=1,
                                          armor=10,
                                          avg_original_hp=20,
                                          avg_melee_damage=7,
                                          immune_to_poison=1,
                                          immune_to_enchantments=1,
                                          level=3,
                                          themes=[E_DISGUISED],
                                          dozy=1,
                                          )
    self.m[M_INVISIBLE_STALKER] = Basic_monster_info(name="the invisible stalker", tile_xy=(12,11),
                                                     description="There is nothing here!",
                                                     fire_resistance=1,
                                                     evasive=1,
                                                     move_cost=1.2,
                                                     melee_cost=0.8,
                                                     avg_original_hp=12,
                                                     avg_melee_damage=5,
                                                     magic_resistance=10,
                                                     immune_to_poison=1,
                                                     melee_verb="buffets",
                                                     level=4,
                                                     themes=[E_DISGUISED],
                                                     flying=1,
                                                     )
    self.m[M_FIRE_LIZARD] = Basic_monster_info(name="the fire lizard", tile_xy=(13,19), 
                                               description="A lesser subspecies of dragon, these lizards have the power to exhale a great gust of flame, which they do often and with great enthusiasm.",
                                               fire_immunity=1,
                                               melee_verb="bites",
                                               avg_original_hp=12,
                                               avg_melee_damage=4,
                                               move_cost=1.2,
                                               can_be_met_in_groups=1,
                                               level=4,
                                               )
    self.m[M_GOBLIN_ARCHER] = Basic_monster_info(name="the goblin archer", tile_xy=(1,4), new_tileset=1,
                                                 description="This goblin will snipe you from a distance and then run away! Little coward...",
                                                 avg_original_hp=6,
                                                 avg_melee_damage=3,
                                                 missile_hit_chance=0.4,
                                                 avg_missile_damage=3,
                                                 level=2,
                                                 can_be_met_in_groups=1,
                                                 themes=[E_GOBLIN,E_HUMANOID],
                                                 size=SZ_SMALL)
    self.m[M_BRIGAND] = Basic_monster_info(name="the brigand", tile_xy=(11,4),
                                           description="This cunning outlaw roams the dungeon, looking for innocents to fleece of their valuables.",
                                           avg_original_hp=9,
                                           missile_hit_chance=0.6,
                                           level=3,
                                           themes=[E_HUMANOID],
                                           avg_melee_damage=6,
                                           avg_missile_damage=5,
                                           can_be_met_in_groups=1,
                                           )
    self.m[M_OGRE] = Basic_monster_info(name="the ogre", tile_xy=(51,18),
                                        description="This enormous ogre carries a huge, spiked club - too big for you to lift in both hands! He will flatten you with it given a chance...",
                                        knockback=1,
                                        move_cost=1.2,
                                        avg_original_hp=15,
                                        avg_melee_damage=8,
                                        melee_cost=1.2,
                                        armor=12,
                                        avoids_fire=0,
                                        avoids_pits=0,
                                        can_swim=1,
                                        level=4,
                                        can_be_met_in_groups=1,
                                        can_be_met_with=[M_GOBLIN,M_ORC],
                                        themes=[E_HUMANOID],
                                        size=SZ_LARGE)
    self.m[M_APPRENTICE] = Basic_monster_info(name="the apprentice", tile_xy=(66,3),
                                              description="A spotty young lad, he looks like he should get out more...",
                                              missile_hit_chance=0.6,
                                              avg_original_hp=10,
                                              avg_missile_damage=3,
                                              avg_melee_damage=2,
                                              magic_resistance=10,
                                              avg_original_mp=30,
                                              level=3,
                                              themes=[E_WIZARD,E_HUMANOID],
                                              size=SZ_SMALL)
    self.m[M_SALAMANDER] = Basic_monster_info(name="the salamander", tile_xy=(36,21),
                                              description="These magical creatures live in the element of fire and cannot leave it.",
                                              fire_immunity=1,
                                              avg_original_hp=12,
                                              moves_through_flame_only=1,
                                              protected_from_missiles=1,
                                              melee_burns=1,
                                              avg_melee_damage=8,
                                              melee_verb="burns",
                                              immune_to_poison=1,
                                              can_be_met_in_groups=1,
                                              level=3,
                                              )
    self.m[M_GOBLIN_SHAMAN] = Basic_monster_info(name="the goblin shaman", tile_xy=(45,13),
                                                 description="The witch-doctor hops up and down, gibbering and clutching his pagan charms and amulets!",
                                                 missile_hit_chance=0.5,
                                                 avg_original_hp=15,
                                                 avg_missile_damage=3,
                                                 avg_melee_damage=3,
                                                 magic_resistance=10,
                                                 avg_original_mp=40,
                                                 level=4,
                                                 themes=[E_HUMANOID,E_GOBLIN],
                                                 can_be_met_with=[M_GOBLIN,M_GOBLIN_ARCHER],
                                                 size=SZ_SMALL)
    self.m[M_WIGHT] = Basic_monster_info(name="the wight", tile_xy=(43,20),
                                         description="This is the unquiet corpse of an ancient warrior. Long ago he was laid to rest, but he has awakened and now shuffles through the dark halls, taking vengeance on all intruders.",
                                         undead=1,
                                         avg_original_hp=15,
                                         fire_resistance=1,
                                         dozy=1,
                                         armor=12,magic_resistance=10,
                                         avg_melee_damage=8,
                                         move_cost=1.1,
                                         avg_original_mp=20,
                                         can_be_met_with=[M_SKELETON],
                                         level=5,
                                         themes=[E_UNDEAD],
                                         )
    self.m[M_WRAITH] = Basic_monster_info(name="the wraith", tile_xy=(6,20),
                                          description="This undead spirit will chill your blood with its horrible calls!",
                                          undead=1,
                                          flying=1,
                                          evasive=1,
                                          avg_original_hp=12,
                                          move_cost=0.85,
                                          melee_cost=0.85,
                                          magic_resistance=12,
                                          avg_original_mp=30,
                                          melee_verb="touches",
                                          avg_melee_damage=3,
                                          alert=1,
                                          can_be_met_in_groups=1,
                                          level=5,
                                          themes=[E_UNDEAD],
                                          )
    self.m[M_SPIDER] = Basic_monster_info(name="the giant spider", tile_xy=(55,15),
                                          description="YUCK! A giant, creepy, crawly, poisonous spider! Squash it! Better yet, get someone else to squash it for you...",
                                          web_walk=1,
                                          melee_cost=0.85,
                                          avg_original_hp=6,
                                          poison_bite=1,
                                          avg_melee_damage=3,
                                          melee_verb="bites",
                                          dozy=1,
                                          can_be_met_in_groups=1,
                                          level=3,
                                          themes=[E_CREEPY_CRAWLY],
                                          )
    self.m[M_SNAKE] = Basic_monster_info(name="the pit viper", tile_xy=(30,16),
                                         description="Snakes are generally inoffensive, unless taken by surprise, in which case they may bite in self-defense. Usually fatally. Or unless they're the aggressive sort. Is this the aggressive sort...?",
                                         melee_cost=0.5,
                                         melee_hit_chance=1,
                                         avg_original_hp=4,
                                         move_cost=0.7,
                                         poison_bite=2,
                                         melee_verb="bites",
                                         avg_melee_damage=2,
                                         dozy=1,
                                         size=SZ_SMALL,
                                         can_be_met_in_groups=1,
                                         level=3,
                                         themes=[E_CREEPY_CRAWLY],
                                          )
    self.m[M_SORCERER] = Basic_monster_info(name="the sorcerer", tile_xy=(34,3),
                                            description="This evil wizard is angry that you have disturbed his studies! He knows dozens of spells with which to punish your transgression, each more unpleasant than the last.",
                                            treasure_carrier=1,
                                            avg_original_mp=60,
                                            avg_original_hp=18,
                                            armor=8,
                                            magic_resistance=12,
                                            alert=1,
                                            can_be_met_with=[M_APPRENTICE,M_GOBLIN],
                                            level=5,
                                            themes=[E_WIZARD,E_HUMANOID],
                                            )
    self.m[M_DARK_ELF] = Basic_monster_info(name="the drow", tile_xy=(43,4),
                                            description="Most elves are creatures of peace and goodness. But this dark elf, or drow, turned long ago from the paths of good and righteousness. Now he walks the path of ... kicking your ass!",
                                            immune_to_poison=1,
                                            key_carrier=1,
                                            avg_original_hp=25,
                                            move_cost=0.7,
                                            melee_cost=0.5,
                                            melee_hit_chance=0.8,
                                            poison_bite=1,
                                            armor=12,
                                            magic_resistance=14,
                                            melee_verb="stabs",
                                            avg_melee_damage=5,
                                            alert=1,
                                            avg_original_mp=100,
                                            can_be_met_alone=0, # never placed randomly
                                            level=7
                                            )
    self.m[M_FIREDRAKE] = Basic_monster_info(name="the Firedrake", tile_xy=(32,12),
                                             description="The Firedrake is a great dragon, covered in red and golden scales, with wisps of flame escaping from its huge reptilian nostrils. Alas for you, you must defeat it to progress any further.",
                                             fire_immunity=1,
                                             flying=1,
                                             avg_original_hp=35,
                                             move_cost=0.6,
                                             immune_to_poison=1,
                                             armor=14,
                                             magic_resistance=14,
                                             melee_verb="claws", # if changing this, change actions.py
                                             avg_melee_damage=7,
                                             dozy=1,
                                             avoids_pits=0,
                                             key_carrier=1,
                                             dragon=1,
                                             level=9,
                                             can_be_met_alone=0, # never placed randomly
                                             size=SZ_LARGE)
    self.m[M_ORC] = Basic_monster_info(name="the orc warrior", tile_xy=(11,13),
                                       description="Ere we go, ere we go, ere we go...",
                                       avg_melee_damage=5,
                                       avg_original_hp=9,
                                       level=3,
                                       can_be_met_in_groups=1,
                                       can_be_met_with=[M_GOBLIN],
                                       themes=[E_ORC,E_HUMANOID],
                                       )
    self.m[M_ORC_CAPTAIN] = Basic_monster_info(name="the orc captain", tile_xy=(6,21),
                                               description="This big orc got to be the boss by being the biggest, the toughest, and the meanest. AND he's got a big chunky crossbow. Anyone want to argue?",
                                               missile_hit_chance=0.6,
                                               avg_original_hp=17,
                                               avg_missile_damage=7,
                                               armor=10,
                                               avg_melee_damage=7,
                                               magic_resistance=9,
                                               move_cost=1.1,
                                               treasure_carrier=1,
                                               can_be_met_with=[M_ORC],
                                               level=4,
                                               themes=[E_ORC,E_HUMANOID]
                                               )
    self.m[M_SEA_SERPENT] = Basic_monster_info(name="the water serpent", tile_xy=(63,18),
                                               description="Definitely not a good day to go swimming, you decide.",
                                               avg_original_hp=15,
                                               can_swim=1,
                                               moves_through_water_only=1,
                                               protected_from_missiles=1,
                                               avg_melee_damage=9,
                                               move_cost=0.9,
                                               melee_verb="bites",
                                               size=SZ_LARGE,
                                               can_be_met_in_groups=1,
                                               level=4
                                               )    
mlib = Monster_library()

